﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.IoTManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.IoTManagement.MeterDeviceVMs
{
    public partial class MeterDeviceListVM : BasePagedListVM<MeterDevice_View, MeterDeviceSearcher>
    {
        
        protected override IEnumerable<IGridColumn<MeterDevice_View>> InitGridHeader()
        {
            return new List<GridColumn<MeterDevice_View>>{
                
                this.MakeGridHeader(x => x.MeterDevice_DeviceCode).SetTitle(@Localizer["Page.设备编号"].Value),
                this.MakeGridHeader(x => x.MeterDevice_DeviceName).SetTitle(@Localizer["Page.设备名称"].Value),
                this.MakeGridHeader(x => x.MeterDevice_DeviceType).SetTitle(@Localizer["Page.设备类型"].Value),
                this.MakeGridHeader(x => x.MeterDevice_Location).SetTitle(@Localizer["Page.安装位置"].Value),
                this.MakeGridHeader(x => x.MeterDevice_Area).SetTitle(@Localizer["Page.所属区域"].Value),
                this.MakeGridHeader(x => x.MeterDevice_Manufacturer).SetTitle(@Localizer["Page.制造商"].Value),
                this.MakeGridHeader(x => x.MeterDevice_InstallDate).SetTitle(@Localizer["Page.安装日期"].Value),
                this.MakeGridHeader(x => x.MeterDevice_CommAddress).SetTitle(@Localizer["Page.通讯地址"].Value),
                this.MakeGridHeader(x => x.MeterDevice_CommProtocol).SetTitle(@Localizer["Page.通讯协议"].Value),
                this.MakeGridHeader(x => x.MeterDevice_Status).SetTitle(@Localizer["Page.状态"].Value),
                this.MakeGridHeader(x => x.MeterDevice_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.MeterDevice_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.MeterDevice_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.MeterDevice_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.MeterDevice_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<MeterDevice_View> GetSearchQuery()
        {
            var query = DC.Set<MeterDevice>()
                
                .CheckContain(Searcher.DeviceCode, x=>x.DeviceCode)
                .CheckContain(Searcher.DeviceName, x=>x.DeviceName)
                .CheckEqual(Searcher.DeviceType, x=>x.DeviceType)
                .CheckContain(Searcher.Location, x=>x.Location)
                .CheckContain(Searcher.Area, x=>x.Area)
                .CheckContain(Searcher.Manufacturer, x=>x.Manufacturer)
                .CheckBetween(Searcher.InstallDate?.GetStartTime(), Searcher.InstallDate?.GetEndTime(), x => x.InstallDate, includeMax: false)
                .CheckContain(Searcher.CommAddress, x=>x.CommAddress)
                .CheckEqual(Searcher.CommProtocol, x=>x.CommProtocol)
                .CheckEqual(Searcher.Status, x=>x.Status)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new MeterDevice_View
                {
				    ID = x.ID,
                    
                    MeterDevice_DeviceCode = x.DeviceCode,
                    MeterDevice_DeviceName = x.DeviceName,
                    MeterDevice_DeviceType = x.DeviceType,
                    MeterDevice_Location = x.Location,
                    MeterDevice_Area = x.Area,
                    MeterDevice_Manufacturer = x.Manufacturer,
                    MeterDevice_InstallDate = x.InstallDate,
                    MeterDevice_CommAddress = x.CommAddress,
                    MeterDevice_CommProtocol = x.CommProtocol,
                    MeterDevice_Status = x.Status,
                    MeterDevice_Remark = x.Remark,
                    MeterDevice_CreateTime = x.CreateTime,
                    MeterDevice_UpdateTime = x.UpdateTime,
                    MeterDevice_CreateBy = x.CreateBy,
                    MeterDevice_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class MeterDevice_View: MeterDevice
    {
        
        public string MeterDevice_DeviceCode { get; set; }
        public string MeterDevice_DeviceName { get; set; }
        public MeterDeviceTypeEnum? MeterDevice_DeviceType { get; set; }
        public string MeterDevice_Location { get; set; }
        public string MeterDevice_Area { get; set; }
        public string MeterDevice_Manufacturer { get; set; }
        public DateTime? MeterDevice_InstallDate { get; set; }
        public string MeterDevice_CommAddress { get; set; }
        public DriverTypeEnum? MeterDevice_CommProtocol { get; set; }
        public EquipStatusEnum? MeterDevice_Status { get; set; }
        public string MeterDevice_Remark { get; set; }
        public DateTime? MeterDevice_CreateTime { get; set; }
        public DateTime? MeterDevice_UpdateTime { get; set; }
        public string MeterDevice_CreateBy { get; set; }
        public string MeterDevice_UpdateBy { get; set; }

    }

}